00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00033
00034 require_once (PATH_TO_ROOT."messaging/classes/class.messaging_view.inc.php");
00035
00036 class MessagingUserSearch extends MessagingView {
00037
00043 private $teams;
00044
00050 private $forename;
00051
00057 private $name;
00058
00064 private $course;
00065
00071 private $useSearchForBuddylist;
00072
00077 public function __construct($messaging) {
00078
00079 parent::__construct($messaging);
00080 }
00081
00086 protected function initView() {
00087 $this->forename = NULL;
00088 $this->name = NULL;
00089 $this->course = NULL;
00090
00091 if(isset($_POST["useSearchForBuddylist"])) {
00092 if($_POST["useSearchForBuddylist"] == "true")
00093 $this->useSearchForBuddylist = true;
00094 else
00095 $this->useSearchForBuddylist = false;
00096 }
00097
00098 if(isset($_GET["useSearchForBuddylist"])) {
00099 if($_GET["useSearchForBuddylist"] == "true")
00100 $this->useSearchForBuddylist = true;
00101 else
00102 $this->useSearchForBuddylist = false;
00103 }
00104
00105 $this->teams = TeamList::getTeams($_SESSION["course"]);
00106
00107 return true;
00108 }
00109
00114 protected function checkActions() {
00115
00116 return true;
00117 }
00118
00125 public function echoSearchForm($useSearchForBuddylist = false) {
00126 if($useSearchForBuddylist) {
00127 $useSearchForBuddylist = "true";
00128 }
00129 else {
00130 $useSearchForBuddylist = "false";
00131 }
00132
00133
00134 echo "<form id='search' method='post' action='".PATH_TO_ROOT.SCRIPT_NAME."'> <table class='tableBorder' width='100%'>";
00135 Output::echoTableHead(Output::getIcon("icon_search", $this->translate->_("Suche Benutzer")) .$this->translate->_("Suche Benutzer"));
00136 echo "<tr><td class='tableCell'>".Utilities::helpCode(669) ."
00137 <table border='0' width='100%'><tr><td>
00138 <p class='pForm'><input type='hidden' name='useSearchForBuddylist' id='useSearchForBuddylist' value='".$useSearchForBuddylist."' /></p>
00139 <p class='pForm'><input type='hidden' name='searchAction' value='search' /></p>
00140 <p class='pForm'><input type='hidden' name='Empfaenger' value=\"".(isset($_POST["Empfaenger"]) ? $_POST["Empfaenger"] : "") ."\" /></p>
00141 <p class='pForm'><input type='hidden' name='Betreff' value=\"".(isset($_POST["Betreff"]) ? $_POST["Betreff"] : "") ."\" /></p>
00142 <p class='pForm'><input type='hidden' name='Nachricht' value=\"".(isset($_POST["Nachricht"]) ? $_POST["Nachricht"] : "") ."\" /></p>
00143 <p class='pForm'><input type='hidden' name='asEmail' value=\"".(isset($_POST["asEmail"]) ? $_POST["asEmail"] : "") ."\" /></p>
00144 </td></tr>
00145 <tr><td>".$this->translate->_("Vorname").":</td><td><p class='pForm'><input type='text' name='searchForename' id='searchForename' size='35' maxlength='35' value='' onkeyup='startAutoSearchTimer(1);' /></p></td></tr>
00146 <tr><td>".$this->translate->_("Nachname").":</td><td><p class='pForm'><input type='text' name='searchName' id='searchName' size='35' maxlength='35' value='' onkeyup='startAutoSearchTimer(1);' /></p></td></tr>";
00147
00148
00149 if (isset($_SESSION["roleID"]) || !empty($this->team)) {
00150 echo "<tr><td>".(isset($_SESSION["roleID"]) ? $this->translate->_("Rolle").(!empty($this->team) ? "/" : ""):
00151 "") .(!empty($this->team) ? $this->translate->_("Team") : "") .":</td><td>";
00152 echo "<p class='pForm'><select name='searchCourse' id='searchCourse' onchange='mayLookup(this.value)' size='1'>
00153 <option value=''>".$this->translate->_("Alle Portalmitglieder")."</option>
00154 <option selected='selected' value='".$_SESSION["course"]."'>".$this->translate->_("Alle Kursmitglieder")."</option>\n";
00155 if (isset($_SESSION["roleID"])) {
00156 $roleSets = RoleSetList::getRoleSets($_SESSION["course"], true);
00157 foreach($roleSets as $roleSet) {
00158 $roleIDs = array();
00159 foreach($roleSet->getRoles() as $role) {
00160 $roleIDs[] = $role->getID();
00161 }
00162 if (empty($roleIDs)) continue;
00163 echo "<option value='r".implode(",", $roleIDs) ."'>".Data::toHTML($roleSet->getName(), false) ."</option>\n";
00164 foreach($roleSet->getRoles() as $role) {
00165 echo "<option value='r".$role->getID() ."'> ".Data::toHTML($role->getName(), false) ."</option>\n";
00166 }
00167 }
00168 }
00169 if (!empty($this->team)) {
00170 foreach($this->team as $team) {
00171 echo "<option value='t".$team->getID() ."'>".Data::toHTML($team->getName(), false) ."</option>\n";
00172 }
00173 }
00174 } else {
00175 echo "<tr><td>".$this->translate->_("Kurs").":</td><td>
00176 <p class='pForm'><select name='searchCourse' id='searchCourse' onchange='mayLookup(this.value)' size='1'>
00177 <option selected='selected' value=''>".$this->translate->_("Alle")."</option>";
00178 $courses = $this->db->get_results("SELECT ID, Name FROM courses WHERE closed=0 ORDER BY Name");
00179
00180 if (!empty($courses)) {
00181 foreach($courses as $course) {
00182 echo "<option value='".$course->ID."'".($course->ID == $_SESSION["course"] ? " selected='selected'" : "") .">".Data::toHTML($course->Name, false) ."</option>";
00183 }
00184 }
00185 }
00186
00187 echo '</select></p>
00188 </td></tr>
00189 </table>
00190 </td></tr>';
00191 Output::echoDialogBottom(array("okButton" => $this->translate->_("Suchen"), "cancelButton" => ""), 1, true);
00192
00193 echo ' </table></form>';
00194 }
00195
00201 public function setSearchForeName($forename) {
00202 $this->forename = Data::toMysql(trim($forename));
00203 }
00204
00210 public function setSearchName($name) {
00211 $this->name = Data::toMysql(trim($name));
00212 }
00213
00219 public function setSearchCourse($course) {
00220 $this->course = Data::toMysql(trim($course));
00221 }
00222
00230 private function getSearchResults($ajax = false) {
00231
00232 if(is_null($this->forename) || is_null($this->name) || is_null($this->course)) {
00233 return NULL;
00234 }
00235
00236 $strSQL = "SELECT DISTINCT(user.ID), user.ShortName, user.Nachname, user.Vorname, user.Usergroup FROM user";
00237 $strWHERE = $strJOIN = "";
00238
00239 if (strlen($this->forename) > 0) {
00240 if ($ajax)
00241 $strWHERE.= " AND user.Vorname LIKE '".$this->forename."%'";
00242 else
00243 $strWHERE.= " AND user.Vorname LIKE '%".$this->forename."%'";
00244 }
00245 if (strlen($this->name) > 0) {
00246 if ($ajax)
00247 $strWHERE.= " AND user.Nachname LIKE '".$this->name."%'";
00248 else
00249 $strWHERE.= " AND user.Nachname LIKE '%".$this->name."%'";
00250 }
00251
00252 if($this->course == "Alle") $this->course = "";
00253
00254 if (!empty($this->course)) {
00255 if ((isset($_SESSION["roleID"]) || !empty($this->team)) && !is_numeric($this->course)) {
00256 $user = array();
00257 if ($this->course{0} == "r") {
00258 foreach(explode(",", substr($this->course, 1)) as $roleID) {
00259 if (($userIDs = UserRoleManagement::getUsersWithRole((int)$roleID))) {
00260 $user = array_merge($user, $userIDs);
00261 }
00262 }
00263 } elseif ($this->course{0} == "t") {
00264 if (($userIDs = UserTeamManagement::getUsersOfTeam((int)substr($this->course, 1)))) {
00265 $user = array_merge($user, $userIDs);
00266 }
00267 }
00268 if (!empty($user)) {
00269 $strWHERE.= " AND user.ID IN (".implode(", ", array_unique($user)) .")";
00270 } else {
00271 $strWHERE.= " AND user.ID < 0";
00272
00273 }
00274 $this->course = Data::toMysql($_SESSION["course"]);
00275
00276 } else {
00277 $strJOIN = " INNER JOIN user_course ON user_course.userID = user.ID";
00278 $strWHERE.= " AND user_course.courseID = '".$this->course."'";
00279 }
00280 }
00281 $strSQL.= $strJOIN." WHERE user.Invisible = '0'" . $strWHERE . " ORDER BY user.Nachname,user.Vorname";
00282
00283 $searchResults = $this->db->get_results($strSQL);
00284
00285 if($this->db->num_rows > 0)
00286 return $searchResults;
00287 else
00288 return NULL;
00289 }
00290
00298 public function echoSearchResults($comboboxVisible = true, $ajax = false) {
00299
00300
00301 $searchResults = $this->getSearchResults ( $ajax );
00302
00303 if (!$comboboxVisible)
00304 echo "<form id='add' method='post' action='".PATH_TO_MESSAGE_NEW."'>\n";
00305 else
00306 echo "<form id='add' method='post' action='" .PATH_TO_BUDDYMANAGEMENT."'>\n";
00307
00308 echo "<table class='tableBorder' width='100%'><tr><td>\n
00309 <p class='pForm'><input type='hidden' name='buddyaction' value='add' /></p>\n
00310 <p class='pForm'><input type='hidden' name='Empfaenger' value=\"" . Data::toHTML ( $_POST ["Empfaenger"] ) . "\" /></p>\n
00311 <p class='pForm'><input type='hidden' name='Betreff' value=\"" . $_POST ["Betreff"] . "\" /></p>\n
00312 <p class='pForm'><input type='hidden' name='Nachricht' value=\"" . $_POST ["Nachricht"] . "\" /></p>\n
00313 <p class='pForm'><input type='hidden' name='asEmail' value=\"" . $_POST ["asEmail"] . "\" /></p>\n
00314 </td></tr>\n";
00315 Output::echoTableHead ( $this->translate->_( "Suchergebnisse" ), 2 );
00316 if (! is_null ( $searchResults )) {
00317 $darkCell = true;
00318
00319 foreach ( $searchResults as $result ) {
00320 $groupLink = Output::getUsergroupPicture ( $result->ID, $result->Usergroup, $this->course );
00321 $darkCell == true ? $class = "tableCellDark" : $class = "tableCell";
00322
00323 if($this->messaging->sameNameUsers($result->ID) <= 0) {
00324 $onclick = "javascript:addUserToRecipients(\"" . Data::toHTML ( $result->Nachname . ", " . $result->Vorname, false ) . "\");";
00325 }
00326 else {
00327 $onclick = "javascript:addUserToRecipients(\"" . Data::toHTML ( $result->Nachname . ", " . $result->Vorname . ", " . $result->ShortName, false ) . "\");";
00328 }
00329
00330 $linkString = "";
00331 if($this->useSearchForBuddylist) {
00332 $linkString = PATH_TO_ROOT."messaging/buddymanagement.php?resultAction=add&selectedUser[]=".$result->ID;
00333 }
00334 else {
00335 $linkString = $onclick;
00336 }
00337 echo " <tr>
00338 <td class='" . $class . "' align='center'><a href='".$linkString."'>" . $groupLink . "</a></td>
00339 <td class='" . $class . "'>";
00340 if($this->useSearchForBuddylist) {
00341 echo "<p class='pForm'><input type='checkbox' name='selectedUser[]' " . ((count($searchResults) == 1 && $ajax == false) ? "checked='checked'" : "") . " value='" . $result->ID . "' /></p>";
00342 }
00343 else {
00344
00345 echo "<p class='pForm'><input type='checkbox' name='selectedUser[]' " . ((count($searchResults) == 1 && $ajax == false) ? "checked='checked'" : "") . " value='" . $result->ID . "' onclick='" . $onclick . "' /></p>";
00346 }
00347 echo " <a href='" . PATH_TO_ROOT . "user/homepage.php?user=" . $result->ID . "'>". Data::toHTML($result->Nachname.", ".$result->Vorname, false). "</a></td>";
00348 echo "</tr>";
00349 $darkCell == true ? $darkCell = false : $darkCell = true;
00350 }
00351 $addCode = "<p class='pForm'>" . $this->translate->_ ( "Auswahl" ) . ": <a href='#' onclick=\"return markAllSearchResults();\">". $this->translate->_ ( "Alle")."</a> | " . "<a href='#' onclick=\"return demarkAllSearchResults();\">". $this->translate->_ ("Keine")."</a> ";
00352 if ($comboboxVisible) {
00353 $addCode .= "<select name='resultAction' size='1'>
00354 <option value='add' selected='selected'>" . $this->translate->_ ( "Hinzufuegen" ) . "</option>
00355 <option value='ignore'>" . $this->translate->_ ( "Ignorieren" ) . "</option>
00356 </select> ";
00357 }
00358 $addCode .= "<input type='submit' name='okButton' value='" . $this->translate->_ ( "Ok" ) . "' /> </p>";
00359 Output::echoDialogBottom ( array ("okButton" => "", "cancelButton" => "" ), 2, true, $addCode );
00360 } else {
00361 Output::errorMessage ( $this->translate->_ ( "Keinen Benutzer gefunden." ) );
00362 }
00363 echo "</table>\n
00364 </form>\n";
00365 }
00366 }
00367
00368 ?>